package org.lanqiao.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.lanqiao.bean.EduUserBean;
import org.lanqiao.myUtils.Myutils;
import org.lanqiao.service.FactoryService;

public class UserInfoMedififySevelet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 获取当前学生的id
		// request.setCharacterEncoding("utf-8");

		int opt = Myutils.getInt(request.getParameter("opt"));

		if (opt == 0) {
			// 修改信息
			String userid = request.getParameter("uid");

			// 把这个id传入数据库中把数据库中的信息找出来传给修改界面
			EduUserBean getEub = FactoryService.getUserInfoManageService().getUserInfoModify(userid);
			
			
			// if(getEub.getUsersex().toString().trim().equals("男")){
			// request.setAttribute("checkM", "checked");
			// request.setAttribute("checkWM", "");
			// }else{
			// request.setAttribute("checkWM", "checked");
			// request.setAttribute("checkM", "");
			// }
			request.setAttribute("userScope", getEub);
			request.getRequestDispatcher("logined/studentadd.jsp").forward(request, response);
		} else if (opt == 1) {
			// 删除功能
			String strDel = request.getParameter("uid");

			boolean deleteResult = FactoryService.getUserInfoManageService().deleteResult(strDel);

			if (deleteResult) {
				request.getRequestDispatcher("UserInfoMedififySevelet?opt=2").forward(request, response);
			}
			// 此处为删除信息
		} else if (opt == 2) {
			// 查询信息
			EduUserBean eub = (EduUserBean) Myutils.getNewInstance(EduUserBean.class);
			// 存名字
			eub.setUsername(request.getParameter("userName"));
			// 存性別
			eub.setUsersex(request.getParameter("userSex"));
			// 存年龄段
			eub.setUserage(Myutils.getInteger(request.getParameter("userAge")));

			eub.setUserage1(Myutils.getInteger(request.getParameter("userAge1")));

			// 存电话
			eub.setUsertel(request.getParameter("userTel"));
			// 存地址
			eub.setUseradress(request.getParameter("userAddress"));
			// 调用查询方法
			List queryList = FactoryService.getUserInfoManageService().getQueryList(eub);

			request.getSession().setAttribute("UserScope", queryList);

			request.getRequestDispatcher("logined/UserInfoManager/userInfoResultSuccess.jsp").forward(request,
					response);
		}
	}

}
